package com.carboy.launch.adapter.setting;

import java.util.ArrayList;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

/**
 * 设置ViewPager Adapter
 */
public class SettingViewPagerAdapter extends PagerAdapter {

	// 总共存在的数量
	private int mViewCount;
	private ArrayList<GridView> listGridView;

	public SettingViewPagerAdapter(int mViewCount,
			ArrayList<GridView> listGridView) {
		super();
		this.mViewCount = mViewCount;
		this.listGridView = listGridView;
	}

	@Override
	public int getCount() {
		return mViewCount;
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == (arg1);
	}

	/**
	 * 添加View
	 */
	@Override
	public Object instantiateItem(View convertView, int position) {
		GridView gridView = listGridView.get(position);
		((ViewPager) convertView).addView(gridView, 0);
		return gridView;
	}

	/**
	 * 防止Required method destroyItem was not overridden异常 因Adapter中的View过多
	 */
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
		object = null;
	}
}
